import java.util.Stack;

class MinStack {
    private Stack<Integer>stack1;
    private Stack<Integer> minstack2;
    public MinStack() {
        stack1=new Stack<>();
        minstack2=new Stack<>();
    }
    
    public void push(int val) {
        stack1.push(val);
        if(minstack2.empty()){
            minstack2.push(val);
        }else{
            int x=minstack2.peek();
            if(val<=x){
                minstack2.push(val);
            }
        }
    }
    
    public void pop() {

        if(!stack1.empty()) {
            int x = stack1.pop();
            if (x == minstack2.peek()) {
                minstack2.pop();
            }
        }
    }
    //只针对普通的栈来说 获取普通栈的栈顶元素
    public int top() {
        if(!stack1.empty()){
            return stack1.peek();
        }
        return -1;
    }
    
    public int getMin() {
        if(minstack2.empty()){
            return -1;
        }
        return minstack2.peek();
    }
}

/**
 * Your MinStack object will be instantiated and called as such:
 * MinStack obj = new MinStack();
 * obj.push(val);
 * obj.pop();
 * int param_3 = obj.top();
 * int param_4 = obj.getMin();
 */